package com.demo2do.fms.admin.dao.supplier;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.appraisal.Appraisal;
import com.demo2do.fms.entity.appraisal.AppraisalTemplate;
import com.demo2do.fms.entity.authority.Branch;
import com.demo2do.fms.entity.supplier.common.Supplier;

/**
 *
 * @author houtao
 *
 */
@Dao("hibernate")
public interface AppraisalDao {
	
	/**
	 * @param adminCreate
	 * @return
	 */
	@Query("SELECT COUNT(*) FROM Appraisal WHERE disabled = false AND adminCreate = :adminCreate")
    public int count(@Variable("adminCreate") boolean adminCreate);
	
	/**
     * @param branch
     * @return
     */
    @Query("SELECT COUNT(*) FROM Appraisal WHERE disabled = false AND branch = :branch")
    public int count(@Variable("branch") Branch branch);
    
    /**
     * @param supplier
     * @return
     */
    @Query("SELECT COUNT(*) FROM Appraisal WHERE disabled = false AND supplier = :supplier")
    public int count(@Variable("supplier") Supplier supplier);
	
	/**
	 * @param template
	 * @return
	 */
	@Query("SELECT COUNT(*) FROM Appraisal WHERE disabled = false AND template = :template")
    public int count(@Variable("template") AppraisalTemplate template);
	
    /**
     * @param adminCreate
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Appraisal WHERE disabled = false AND adminCreate = :adminCreate ORDER BY beginDate DESC")
    public List<Appraisal> list(@Variable("adminCreate") boolean adminCreate, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param branch
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Appraisal WHERE disabled = false AND branch = :branch ORDER BY beginDate DESC")
    public List<Appraisal> list(@Variable("branch") Branch branch, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param supplier
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Appraisal WHERE disabled = false AND supplier = :supplier ORDER BY beginDate DESC")
    public List<Appraisal> list(@Variable("supplier") Supplier supplier, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param template
     * @return
     */
    @Query("FROM Appraisal WHERE disabled = false AND template = :template")
    public List<Appraisal> list(@Variable("template") AppraisalTemplate template);
    
    /**
     * @param name
     * @return
     */
    @Query("FROM Appraisal WHERE disabled = false AND name = :name")
    public Appraisal getByName(@Variable("name") String name);
    
}